import os
import sys

# 将项目根目录添加到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import create_app, db

def update_database():
    """更新数据库表结构"""
    try:
        app = create_app()
        with app.app_context():
            # 添加 liked_posts 列到 users 表
            with db.engine.connect() as conn:
                conn.execute(db.text("""
                    ALTER TABLE users
                    ADD COLUMN liked_posts TEXT DEFAULT '';
                """))
                conn.commit()
            print("数据库更新成功！")
            
    except Exception as e:
        print(f"更新失败：{str(e)}")
        sys.exit(1)

if __name__ == '__main__':
    update_database()